﻿using System;
using System.Net.Mail;

namespace Utility
{
    public class Email
    {
        #region 对外发送电子邮件
        /// <summary>
        /// 对外发送电子邮件
        /// </summary>
        /// <param name="_Receive">接收人，多个用逗号分开</param>
        /// <param name="_MailTitle">邮件标题，默认为‘【亿欣：让生活更美好！】’</param>
        /// <param name="_MailBody">邮件内容</param>
        public static void Send(string _Receive, string _MailTitle, string _MailBody)
        {
            if (_MailTitle == "") { _MailTitle = "【亿欣：让生活更美好！】"; }
            SmtpClient Smtp = new SmtpClient("smtp.gmail.com",25);//mail.orule.cn
            Smtp.EnableSsl = true;
            Smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
            Smtp.Credentials = new System.Net.NetworkCredential("kefu@eexin.com", "www.eexin.com");
            MailMessage Msg = new MailMessage("KeFu@Eexin.com", _Receive, _MailTitle, _MailBody);
            Msg.IsBodyHtml = true;
            Smtp.Send(Msg);
        }
        public static void AsyncSend(string _Receive,string _Title,string _Body)
        {
            AsyncCallback Cb = new AsyncCallback(ProcessSend);
            AsyncDelegateSend Ad = new AsyncDelegateSend(Send);
            IAsyncResult Ar = Ad.BeginInvoke(_Receive,_Title,_Body,Cb,Ad);
        }
        //声明委托
        public delegate void AsyncDelegateSend(string _Receive, string _MailTitle, string _MailBody);
        //回调函数
        public static void ProcessSend(IAsyncResult Ar)
        {
            AsyncDelegateSend andl = (AsyncDelegateSend)Ar.AsyncState;
            andl.EndInvoke(Ar);
        }

        #endregion
    }
}
